#include<bits/stdc++.h>
#define int long long
using namespace std;
int sumof[1919810];
struct car{
    int d;
    int v;
    int a;
    bool now;
    int future;
};
car zz[100005];
int p[100005];

int anz[400005];
int ans2=99999999;
void dfs(int x,int num,int p,int n,int mm,int m){
	//cout<<x<<' '<<num<<' '<<m<<endl;
    if(num==m){
        ans2=min(ans2,p);
        return;
    }
    if(x==mm+1)return;
    if(anz[x]!=0)dfs(x+1,num|anz[x],p+1,n,mm,m);
    dfs(x+1,num,p,n,mm,m);
}
void suan(){
    memset(p,0,sizeof(p));
    memset(sumof,0,sizeof(sumof));
    memset(zz,0,sizeof(zz));
    memset(anz,0,sizeof(anz));
    int n,m,l,v;
    cin>>n>>m>>l>>v;
    for(int i=1;i<=n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        zz[i].d=a;
        zz[i].v=b;
        zz[i].a=c;
    }
    for(int i=1;i<=m;i++){
        int d;
        cin>>d;
        p[i]=d;
        sumof[d]++;
    }
    sort(p+1,p+1+m);
    for(int i=1;i<=l+5;i++){
        sumof[i]+=sumof[i-1];
    }
    int ans1=0;
    int azz=0;
    for(int i=1;i<=n;i++){
        if(zz[i].v>v&&zz[i].a>=0){
            if(sumof[l]-sumof[zz[i].d-1]>0){
                ans1++;
                azz+=pow(2,i-1);
                if(n<2000){
                    for(int j=sumof[zz[i].d-1]+1;j<=sumof[l];j++){
                        anz[j]+=pow(2,i-1);
                    }
                }
                //cout<<i<<endl;
               // cg(1,1,m,sumof[zz[i].d-1]+1,sumof[l]);
            }
        }
        else if(zz[i].v>v&&zz[i].a<0){
            int s=zz[i].d+(v*v-zz[i].v*zz[i].v)/(2*zz[i].a);
            if((v*v-zz[i].v*zz[i].v)%(2*zz[i].a)==0)s--;
            s=min(s,l);
            if(sumof[s]-sumof[zz[i].d-1]>0){
                ans1++;//cout<<i<<endl;
                azz+=pow(2,i-1);
                
                if(n<2000){
                    for(int j=sumof[zz[i].d-1]+1;j<=sumof[s];j++){
						//if(i==4)cout<<j<<endl<<endl<<endl;
						//if(i==4)cout<<anz[j];
                        anz[j]+=pow(2,i-1);
                        //if(i==4)cout<<anz[j]<<endl<<endl;
                    }
                }
               // cg(1,1,m,sumof[zz[i].d-1]+1,sumof[s]);
            }
        }
        else if(zz[i].v<=v&&zz[i].a>0){
            int s=zz[i].d+(v*v-zz[i].v*zz[i].v)/(2*zz[i].a);
            if((v*v-zz[i].v*zz[i].v)%(2*zz[i].a)==0)s++;
            //s=min(s,l);
            if(s>l-1)continue;
            if(sumof[l]-sumof[s-1]>0){
                ans1++;//cout<<i<<endl;
                azz+=pow(2,i-1);
                if(n<2000){
                    for(int j=sumof[s-1]+1;j<=sumof[l];j++){
                        anz[j]+=pow(2,i-1);
                    }
                }
                //cg(1,1,m,sumof[s-1]+1,sumof[l]);
            }
        }
        else{
            continue;
        }
    }

    cout<<ans1<<' ';
    if(n>=2000){
        if(ans1!=0)cout<<m-1;
        else cout<<m;
    }
    ans2=m;
    dfs(1,0,0,n,m,azz);
    if(n<2000){
		cout<<m-ans2;
	}
    cout<<endl;
}
signed main(){
	freopen("detect.in","r",stdin);
	freopen("detect.out","w",stdout);
    int T;
    cin>>T;
    while(T--){
        suan();
    }
}
